<?php
class controller_sys extends model_sys{

	public function __construct() {
		parent::__construct();
	}
	//region 系统设置
	public function system_setup(){
		$this->display('sys/system_setup',array(
		    'basepath' => '/sys/system_setup',
        ));
	}
	public function save()
    {
        $para = $_POST;
        unset($para['hiddencontent']);
        unset($para['client_type']);
        unset($para['uploadbutton']);
        $sql='insert into `@@params` (`name`, `value`) VALUES';
        foreach($para as $key=>$var){
            $sql.=" ('$key', '$var'),";
        }
        $sql = substr($sql,0,strlen($sql)-1);
        $sql.=' on duplicate key update `value`=values(`value`);';
        //echo $sql;
        $this->db->query($sql,0);
        $this->dialogue(array(
            'type' => 'success',
            'text' => '系统设置 - 保存成功',
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
	//endregion

	//region 管理员及权限控制
	/*
	 * 系统权限控制列表
	 */
	public function auth(){
        $this->display('sys/auth',array(
            'datas' => $this->mod_auth_list(),
            'auth_group' => $this->mod_auth_group(),
            'basepath' => '/sys/auth',
        ));
    }

    public function auth_add(){
	    $basepath = '/sys/auth';
	    $auth_group = $this->mod_auth_group();
        $maxsort = $this->table_maxsort('@@auth','sort','1');
	    $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>控制器：</dt><dd><input type="text" name="action" class="int" value="" /></dd></dl>';
        $html .= '<dl><dt>作用说明：</dt><dd><input type="text" name="title" class="int" /></dd></dl>';
        $html .= '<dl><dt>分类：</dt><dd><select type="text" name="type">';
        $html .= '<option value="0" select="selected">不指定</option>';

        if($auth_group){
             foreach($auth_group as $k=>$v){
                 $html .= '<option value="'.$v['id'].'">'.$v['title'].'</option>';
             }
        }

        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>排序：</dt><dd><input type="text" name="sort" class="mint" value="'.$maxsort.'" /></dd><dd class="t">按0,1,2,3的顺序排序</dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    public function auth_edit(){
        $basepath = '/sys/auth';
        $auth_group = $this->mod_auth_group();
        $id = $this->existsKeyInArray('id',$_GET,'N');
        $data = $this->mod_auth_item($id);
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="id" value="'.$data['id'].'" />';
        $html .= '<dl><dt>控制器：</dt><dd><input type="text" name="action" class="int" value="'.$data['action'].'" /></dd></dl>';
        $html .= '<dl><dt>作用说明：</dt><dd><input type="text" name="title" class="int" value="'.$data['title'].'" /></dd></dl>';
        $html .= '<dl><dt>分类：</dt><dd><select type="text" name="type">';
        $html .= '<option value="0"'.(intval($data['type'])==0 ? ' selected="selected"' : '').'>不指定</option>';

        if($auth_group){
            foreach($auth_group as $k=>$v){
                $html .= '<option value="'.$v['id'].'"'.(intval($data['type'])==intval($v['id']) ? ' selected="selected"' : '').'>'.$v['title'].'</option>';
            }
        }

        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>排序：</dt><dd><input type="text" name="sort" class="mint" value="'.$data['sort'].'" /></dd><dd class="t">按0,1,2,3的顺序排序</dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    /*
	* 控制器参数处理
	*/
    private function auth_add_edit_args(){
        $para = $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['id'] = $this->existsKeyInArray('id',$para,'N');
        $args['title'] = $this->existsKeyInArray('title',$para,'S');
        $args['action'] = $this->existsKeyInArray('action',$para,'S');
        $args['type'] = $this->existsKeyInArray('type',$para,'N');
        $args['sort'] = $this->existsKeyInArray('sort',$para,'S');
        if(empty($para['title'])) core::error("控制器名称不能为空");
        if(empty($para['action'])) core::error("控制器不能为空");
        return $args;
    }
    public function auth_add_save(){
        if(!$this->post) core::__403();
        $para = $this->auth_add_edit_args();
        unset($para['id']);
        $insertid = $this->mod_auth_save($para);
        if(!$insertid) core::error("添加[".$para['title']."]失败");
        $this->addLog($this->authid,__FUNCTION__,$insertid,$para['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$para['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/sys/auth");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
	/*
	* 控制器添加或编辑保存处理
	*/
    public function auth_edit_save(){
        if(!$this->post) core::__403();
        $para = $this->auth_add_edit_args();
        $update_args = array('id' => $para['id']);
        unset($para['id']);
        $insertid = $this->mod_auth_save($para, $update_args,true);
        if(!$insertid) core::error("更新[".$para['title']."]失败");
        $this->addLog($this->authid,__FUNCTION__,$update_args['id'],$para['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$para['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/sys/auth");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    public function usergroup(){
        $this->display('sys/usergroup',array(
            'basepath' => 'sys/usergroup',
            'datas' => $this->mod_sysuser_user_group(),
        ));
    }
    /*
     * 后端用户权限设置
     */
    public function usergroup_setting(){
        $id = $this->existsKeyInArray('id',$_REQUEST,true);
        $this->display('sys/usergroup_setting',array(
            'basepath' => 'sys/usergroup_setting',
            'datas' => $this->mod_auth_list(),
            'groupdata' => $this->mod_sysuser_user_group_forid($id),
        ));
    }
    public function usergroup_setting_save(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        $groupid = $this->existsKeyInArray('groupid',$_POST,'N');
        if(empty($groupid)) core::error('用户组参数不正确');
        if(empty($ids)) core::error('没有选择任何权限');
        //core::error('groupid='.$groupid);
        //保存数据
        $updateid = $this->mod_user_group_setting_save($ids,$groupid);
        if(!$updateid) core::error('用户组权限设置失败');
        $this->addLog($this->authid,__FUNCTION__,$updateid,'用户组权限设置');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "用户组权限设置成功",
            'auto' => true,
            'yes'  => array(
                'text' => '知道了',
                'func' => 'JumpMainFrame("/sys/usergroup");',
            ),
        ));
    }
    /*
    * 系统管理员
    */
    private function userlist_get_args($get){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['usergroup'] = $this->existsKeyInArray('usergroup',$para,'N');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        return $args;
    }
    private function userlist_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['usergroup'])) $page_args['usergroup'] = $args['usergroup'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    public function userlist(){
        $get = true;
        $args = $this->userlist_get_args($get);
        $page_args = $this->userlist_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_sysuserlist($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $ug = $this->mod_sysuser_user_group();
        $usergroup = array();
        foreach($ug as $k=>$v){
            $usergroup[$v['id']] = $v['title'];
        }

        $this->display("sys/userlist",array(
            'basepath' => '/sys/userlist',
            'usergroup' => $ug,
            'usergroup1' => $usergroup,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/sys/userlist',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    /*
     * 添加系统管理员
     */
	public function userlist_add(){
        $basepath = '/sys/userlist';
        $usergroup = $this->mod_sysuser_user_group();

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>登录帐号：</dt><dd><input type="text" name="username" class="int" value="" /></dd></dl>';
        $html .= '<dl><dt>默认密码：</dt><dd><input type="text" name="password" class="int" /></dd></dl>';
        $html .= '<dl><dt>所属部门：</dt><dd><select type="text" name="usergroup">';
        $html .= '<option value="0" selected="selected">暂不指定</option>';
        if($usergroup){
            foreach($usergroup as $k=>$v){
                $html .= '<option value="'.$v['id'].'">'.$v['title'].'</option>';
            }
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>帐户状态：</dt><dd><select type="text" name="enable">';
        $html .= '<option value="1" selected="selected">启用</option>';
        $html .= '<option value="0">禁用</option>';
        $html .= '</select>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    public function userlist_edit(){
	    if(!$this->post) core::__403();
	    $uid = intval($_REQUEST['uid']);
	    if(!$uid) core::error('操作失败，请返回重试');
        $basepath = '/sys/userlist';
        $usergroup = $this->mod_sysuser_user_group();
        $data = $this->mod_sysuser_item($uid);
        if(!$data) core::error('当前选择的管理帐号不存在');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="uid" value="'.$data['uid'].'" />';
        $html .= '<dl><dt>登录帐号：</dt><dd><input type="text" name="username" class="int" value="'.$data['username'].'" /></dd></dl>';
        $html .= '<dl><dt>默认密码：</dt><dd><input type="text" name="password" class="int" /></dd><dd class="t">不修改留空</dd></dl>';
        $html .= '<dl><dt>所属部门：</dt><dd><select type="text" name="usergroup">';
        $html .= '<option value="0"'.(intval($data['usergroup'])==0 ? 'selected="selected"' : '').'>暂不指定</option>';
        if($usergroup){
            foreach($usergroup as $k=>$v){
                $html .= '<option value="'.$v['id'].'"'.(intval($data['usergroup'])==intval($v['id']) ? 'selected="selected"' : '').'>'.$v['title'].'</option>';
            }
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>帐户状态：</dt><dd><select type="text" name="enable">';
        $html .= '<option value="1"'.(intval($data['enable'])==1 ? 'selected="selected"' : '').'>启用</option>';
        $html .= '<option value="0"'.(intval($data['enable'])==0 ? 'selected="selected"' : '').'>禁用</option>';
        $html .= '</select>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
	/*
	* 系统管理员表参数
	*/
    private function userlist_add_edit_args()
    {
        $args['uid'] = $this->existsKeyInArray('uid',$_POST,'N');
        $args['username'] = $this->existsKeyInArray('username',$_POST,'S');
        $args['password'] = $this->existsKeyInArray('password',$_POST,'S');
        $args['usergroup'] = $this->existsKeyInArray('usergroup',$_POST,'N');
        $args['enable'] = $this->existsKeyInArray('enable',$_POST,'N');
        return $args;
    }
    /*
     * 保存添加的系统管理员
     */
    public function userlist_add_save(){
        if(!$this->post) core::__403();
        $args = $this->userlist_add_edit_args();
        if(empty($args['username'])) core::error('帐号不能为空');
        if(empty($args['password'])) core::error('密码不能为空');
        unset($args['uid']);
        $keyt = $this->randString(4);
        $pass = $this->encrypt($args['password'],'E',$keyt);
        $args['password'] = $pass;
        $args['keyt'] = $keyt;
        $args['regtime'] = time();
		$args['regip'] = $this->ip(true);
        $insertid = $this->table_row_save('@@admin_members',$args);
        if(!$insertid) core::error("添加[".$args['username']."]失败");
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$insertid,$args['username']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['username']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/userlist");',
            ),
        ));
    }
    /*
     * 保存编辑的系统管理员
     */
    public function userlist_edit_save(){
        if(!$this->post) core::__403();
        $args = $this->userlist_add_edit_args();
        if(empty($args['username'])) core::error('帐号不能为空');
        if(empty($args['password'])){
            unset($args['password']);
        }else{
            $keyt = $this->randString(4);
            $pass = $this->encrypt($args['password'],'E',$keyt);
            $args['password'] = $pass;
            $args['keyt'] = $keyt;
        }
        $uid = $args['uid'];
        unset($args['uid']);
        $updateid = $this->table_row_save('@@admin_members',$args,array('uid'=>$uid),true);
        if(!$updateid) core::error("更新[".$args['username']."]失败");
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$uid,$args['username']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$args['username']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/userlist");',
            ),
        ));
    }
    # 删除管理员
    public function userlist_delete()
    {
        $uid = $this->existsKeyInArray('uid', $_GET,'N');
        $username = $this->existsKeyInArray('username',$_GET,'S');
        $deleid = $this->db->delete('@@admin_members',array('uid'=>$uid));
        if(!$deleid) core::error('操作失败');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除管理员[".$username."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/userlist");',
            ),
        ));
    }
	/*
	* 管理员登录日志
	*/
	private function admin_get_args($get){
		$para = $get ? $_GET : $_POST;
        $args = array();
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,true,$this->pagesize);
        return $args;
	}
	private function admin_page_args($args){
		$page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
	}
	public function adminloger(){
		$get = true;
        $args = $this->admin_get_args($get);
        $page_args = $this->admin_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_admin_loger($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("sys/admin_loger",array(
            'basepath' => '/sys/adminloger',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
	}

	//endregion
    # region 退出登录
    //退出登录
    public function logout(){
        if(array_key_exists($this->user_session, $_SESSION) && $_SESSION[$this->user_session]) {
            $this->user = unserialize($_SESSION[$this->user_session]);
            $uid = $this->user['uid'];
            $this->db->query("UPDATE `@@admin_session` SET `isonline`=0 WHERE `uid`={$uid}",0);
        }
        unset($_SESSION[$this->user_session]);
        header('Location: /user/login');
    }
    # endregion
    # region 修改自己的登录密码
    public function modifyloginpass()
    {
        $uid = intval($this->user['uid']);
        if(!$uid) core::error('操作失败，请返回重试');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="/sys/modifyloginpass_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="uid" value="'.$uid.'" />';
        $html .= '<dl><dt>旧登录密码：</dt><dd><input type="text" name="oldpass" class="int" placeholder="输入你当前的登录密码" /></dd></dl>';
        $html .= '<dl><dt>新登录密码：</dt><dd><input type="text" name="newpass" class="int" placeholder="输入新的登录密码" /></dd></dl>';
        $html .= '<dl><dt>确认新密码：</dt><dd><input type="text" name="repass" class="int" placeholder="再次确认新的登录密码" /></dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    public function modifyloginpass_save()
    {
        $uid = intval($this->user['uid']);
        if(!$uid) core::error('操作失败，请返回重试');
        $oldpass = $this->existsKeyInArray('oldpass',$_POST,'S');
        $newpass = $this->existsKeyInArray('newpass',$_POST,'S');
        $repass = $this->existsKeyInArray('repass',$_POST,'S');
        if(empty($oldpass)) core::error('旧的登录密码不能为空');
        if(empty($newpass)) core::error('新的登录密码不能为空');
        if($repass!=$newpass) core::error('新的登录密码两次输入不一致');

        if(!ctype_alnum($repass)) core::error('密码须是字母和数字的组合');
        if(strlen($newpass) < 6 ) core::error('密码不能少于6个字符');
        if(ctype_digit($newpass)) core::error('密码不能全部用数字,须是字母和数字的组合');
        if(ctype_alpha($newpass)) core::error('密码不能全部用字母,须是字母和数字的组合');
        $string_up_low_sizeof = $this->up_low_sizeof($newpass);
        if(empty($string_up_low_sizeof[0])) core::error('密码须有最少一个大写字符');
        if(empty($string_up_low_sizeof[1])) core::error('密码须有最少一个小写字符');

        # 旧密码是否正确
        $data = $this->getRow('@@admin_members','`password`,`keyt`',array(
            'uid'=>$this->user['uid'],
            'isdelete'=>0
            ));
        if(!$data) core::error('帐号异常');
        $db_password = $data['password'];

        $db_keyt = $data['keyt'];
        $pass = $this->encrypt($oldpass,'E',$db_keyt);
        if($pass!=$db_password) core::error('旧的登录密码错误');

        $keyt = $this->randString(4);
        $pass = $this->encrypt($newpass,'E',$keyt);

        $args = array(
            'password' => $pass,
            'keyt' => $keyt,
        );

        $updateid = $this->table_row_save('@@admin_members',$args,array('uid'=>$uid),true);
        if(!$updateid) core::error("密码修改失败");
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$uid,$uid);
        unset($_SESSION[$this->user_session]);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "登录密码修改成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$.reload("/user/login");',
            ),
        ));

    }
    # endregion
    //region 自定义导航
	/*
	* 自定义导航
	*/
	public function mainnav(){
		$this->display('sys/mainnav',array(
			'basepath' => '/sys/mainnav',
			'datas' => $this->mod_mainnav(),
		));
	}
	/*
	* 添加系统导航
	*/
	public function mainnav_add(){
        $basepath = '/sys/mainnav';

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>标题：</dt><dd><input type="text" name="title" class="int" value="" /></dd></dl>';
        $html .= '<dl><dt>说明：</dt><dd><input type="text" name="subtitle" class="int" /></dd></dl>';
		$html .= '<dl><dt>链接：</dt><dd><input type="text" name="url" class="int" /></dd></dl>';
        $html .= '<dl><dt>分类：</dt><dd><select type="text" name="groupid">';
        $html .= '<option value="0" selected="selected">主导航</option>';
        if($this->mainnav_group){
            foreach($this->mainnav_group as $k=>$v){
                $html .= '<option value="'.$k.'">'.$v.'</option>';
            }
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>图示：</dt><dd><select name="hotnew">';
        $html .= '<option value="0" selected="selected">无图</option>';
        $html .= '<option value="1">热图</option>';
        $html .= '<option value="2">新图</option>';
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>状态：</dt><dd><select type="text" name="state">';
        $html .= '<option value="1" selected="selected">启用</option>';
        $html .= '<option value="0">禁用</option>';
        $html .= '</select>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
	/*
	* 添加系统导航
	*/
	public function mainnav_edit(){
        $basepath = '/sys/mainnav';
		$id = $this->existsKeyInArray('id',$_GET,'N');
		$v = $this->mod_mainnav_item($id);
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="edit_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
		$html .= '<input type="hidden" name="id" value="'.$id.'" />';
        $html .= '<dl><dt>标题：</dt><dd><input type="text" name="title" class="int" value="'.$v['title'].'" /></dd></dl>';
        $html .= '<dl><dt>说明：</dt><dd><input type="text" name="subtitle" class="int" value="'.$v['subtitle'].'" /></dd></dl>';
		$html .= '<dl><dt>链接：</dt><dd><input type="text" name="url" class="int" value="'.$v['url'].'" /></dd></dl>';
        $html .= '<dl><dt>分类：</dt><dd><select name="groupid">';
        $html .= '<option value="0" selected="selected">主导航</option>';
        if($this->mainnav_group){
            foreach($this->mainnav_group as $k=>$sv){
                $html .= '<option value="'.$k.'" '.(intval($v['groupid'])==$k ? ' selected="selected"' : '').'">'.$sv.'</option>';
            }
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>图示：</dt><dd><select name="hotnew">';
        $html .= '<option value="0" '.(intval($v['hotnew'])==0 ? ' selected="selected"' : '').'>无图</option>';
        $html .= '<option value="1" '.(intval($v['hotnew'])==1 ? ' selected="selected"' : '').'>热图</option>';
        $html .= '<option value="2" '.(intval($v['hotnew'])==2 ? ' selected="selected"' : '').'>新图</option>';
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>状态：</dt><dd><select type="text" name="state">';
        $html .= '<option value="1" '.(intval($v['state'])==1 ? ' selected="selected"' : '').'>启用</option>';
        $html .= '<option value="0" '.(intval($v['state'])==0 ? ' selected="selected"' : '').'>禁用</option>';
        $html .= '</select>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=edit_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
	/*
	* 获取及过滤导航的参数
	*/
	public function main_nav_get_args($get){
		$para = $get ? $_GET : $_POST;
		$args = array();
		$args['id'] = $this->existsKeyInArray('id',$para,'N');
		$args['title'] = $this->existsKeyInArray('title',$para,'S');
		$args['subtitle'] = $this->existsKeyInArray('subtitle',$para,'S');
		$args['url'] = $this->existsKeyInArray('url',$para,'S','#');
		$args['groupid'] = $this->existsKeyInArray('groupid',$para,'N');
        $args['hotnew'] = $this->existsKeyInArray('hotnew',$para,'N');
		$args['state'] = $this->existsKeyInArray('state',$para,'N');
		return $args;
		
	}
	/* 
	* 保存编辑的导航数据
	*/
	public function mainnav_add_save(){
		if(!$this->post) core::__403();
		$args = $this->main_nav_get_args(false);
		if(empty($args['title'])) core::error('导航标题不能为空');
		unset($args['id']);
		$insertid = $this->table_row_save('@@mainnav',$args);
		if(!$insertid) core::error('添加【'.$args['title'].'】失败');
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$insertid,$args['title']);
		$this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/mainnav");',
            ),
        ));
	}
	/* 
	* 保存编辑的导航数据
	*/
	public function mainnav_edit_save(){
		if(!$this->post) core::__403();
		$args = $this->main_nav_get_args(false);
		$editid = $args['id'];
		unset($args['id']);
		if(empty($args['title'])) core::error('导航标题不能为空');
		$updateid = $this->table_row_save('@@mainnav',$args,array('id'=>$editid),true);
		if(!$updateid) core::error('更新【'.$args['title'].'】失败');
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$editid,$args['title']);
		$this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/mainnav");',
            ),
        ));
	}

	//endregion

	//region 积分种类管理
    public function score_category_state(){
	    $id = $this->existsKeyInArray('id',$_GET,'N');
	    if(!$id) core::__403();
	    $updateid = $this->mod_score_category_state($id);
	    if(!$updateid) core::error('状态更新失败');
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$updateid,'状态更新');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "状态更新成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/score_category");',
            ),
        ));
    }
    //处理数据列表参数
    public function score_category_get_args($get = true){
	    $para = $get ? $_GET : $_POST;
	    $args = array(
	        'sKey' => $this->existsKeyInArray('sKey',$para,'S'),
            'ps' => $this->existskeyInArray('ps',$para,'N',$this->pagesize),
        );
	    return $args;
    }
    //处理数据列表分页参数
    public function score_category_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function score_category(){
        //echo __FUNCTION__;
        //获取参数
        $args = $this->score_category_get_args(true);
        //获取当前页码
        $args['page_current'] = $this->get_page();
        //重组分布链接参数
        $page_args = $this->score_category_page_args($args);
        //拉取条件数据
        $datas = $this->mod_score_category_list($args);
        //计算数据最大分页数
        $args['page_max'] = $this->get_maxpage($args['ps'], $datas['record']);
        //显示模板
	    $this->display('score/category',array(
            'basepath' => '/sys/score_category',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    public function score_category_delete(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if(!$id) core::__403();
        if($id<=4) core::error('系统默认积分种类无法删除');
        $deleteid = $this->db->delete('@@score_category',array('id'=>$id));
        if(!$deleteid) core::error('删除操作失败');
        //记录操作日志
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/score_category");',
            ),
        ));
    }
    public function score_category_add()
    {
        $basepath = '/sys/score_category';
        $id = $this->existsKeyInArray('id', $_GET, 'N');
        $v = $this->mod_score_category_item($id);
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="' . $basepath . '_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>种类名称：</dt><dd><input type="text" name="title" class="int" value="" /></dd></dl>';
        $html .= '<dl><dt>兑换汇率：</dt><dd>1 元兑换 <input type="text" name="toscore" class="mint" value="" /> 积分</dd></dl>';
        $html .= '<dl><dt>&nbsp;</dt><dd><input type="text" name="tocoin" class="mint" value="" /> 积分兑换 1 元</dd></dl>';
        $html .= '<dl><dt>当前状态：</dt><dd><select type="text" name="state">';
        $html .= '<option value="1" >启用</option>';
        $html .= '<option value="0" selected="selected">禁用</option>';
        $html .= '</select>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes' => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no' => array(
                'text' => '关闭',
            ),
        ));
    }
    public function score_category_edit(){
        $basepath = '/sys/score_category';
        $id = $this->existsKeyInArray('id',$_GET,'N');
        $v = $this->mod_score_category_item($id);
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="edit_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="id" value="'.$id.'" />';
        $html .= '<dl><dt>种类名称：</dt><dd><input type="text" name="title" class="int" value="'.$v['title'].'" /></dd></dl>';
        $html .= '<dl><dt>兑换汇率：</dt><dd>1 元兑换 <input type="text" name="toscore" class="mint" value="'.$v['toscore'].'" /> 积分</dd></dl>';
        $html .= '<dl><dt>&nbsp;</dt><dd><input type="text" name="tocoin" class="mint" value="'.$v['tocoin'].'" /> 积分兑换 1 元</dd></dl>';
        $html .= '<dl><dt>当前状态：</dt><dd><select type="text" name="state">';
        $html .= '<option value="1" '.(intval($v['state'])==1 ? ' selected="selected"' : '').'>启用</option>';
        $html .= '<option value="0" '.(intval($v['state'])==0 ? ' selected="selected"' : '').'>禁用</option>';
        $html .= '</select>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=edit_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //积分种类新增、编辑参数重组
    private function score_category_add_edit_args($get=false){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'id' => $this->existsKeyInArray('id',$para,'N'),
            'title' => $this->existsKeyInArray('title',$para,'S'),
            'toscore' => $this->existsKeyInArray('toscore',$para,'N'),
            'tocoin' => $this->existsKeyInArray('tocoin',$para,'N'),
            'state' => $this->existsKeyInArray('state',$para,'N'),
        );
        if(empty($args['title'])) core::error('积分种类的名称不能为空');
        //当 $toscore 为0时本兑换方式不启用
        return $args;
    }
    //保存新增的积分种类数据
    public function score_category_add_save(){
        if(!$this->post) core::__403();
        $args = $this->score_category_add_edit_args(false);
        unset($args['id']);
        $insertid = $this->table_row_save('@@score_category',$args);
        if(!$insertid) core::error('添加【'.$args['title'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$insertid,$args['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/score_category");',
            ),
        ));
    }
    //保存编辑的积分种类数据
    public function score_category_edit_save(){
        if(!$this->post) core::__403();
        $args = $this->score_category_add_edit_args(false);
        $editid = $args['id'];
        unset($args['id']);
        $updateid = $this->table_row_save('@@score_category',$args,array('id'=>$editid),true);
        if(!$updateid) core::error('更新【'.$args['title'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$editid,$args['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/score_category");',
            ),
        ));
    }
    //endregion

    //region 银行列表设置
    //处理数据列表参数
    public function banklist_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'sKey' => $this->existsKeyInArray('sKey',$para,'S'),
            'ps' => $this->existskeyInArray('ps',$para,'N',$this->pagesize),
        );
        return $args;
    }
    //处理数据列表分页参数
    public function banklist_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function banklist(){
        //获取参数
        $args = $this->banklist_get_args(true);
        //获取当前页码
        $args['page_current'] = $this->get_page();
        //重组分布链接参数
        $page_args = $this->banklist_page_args($args);
        //拉取条件数据
        $datas = $this->mod_banklist_list($args);
        //计算数据最大分页数
        $args['page_max'] = $this->get_maxpage($args['ps'], $datas['record']);
        //显示模板
        $this->display('sys/banklist',array(
            'basepath' => '/sys/banklist',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }

    //新增行
    public function banklist_add()
    {
        $this->display('sys/banklist_add',array(
            'basepath' => '/sys/banklist',
            'page_url' => '',
            'page_current' => 1,
            'maxsort' => 1,
        ));
    }
    //编辑行
    public function banklist_edit(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if($id==24) core::error('管理员充值不能编辑');
        $this->display('sys/banklist_edit', array(
            'basepath' => '/sys/banklist',
            'data' => $this->mod_banklist_item($id),
        ));
    }
    //状态更新
    public function banklist_state()
    {
        $id = $this->existsKeyInArray('id',$_REQUEST,'N');
        if(!$id) core::error('参数错误');
        if($id==24) core::error('管理员充值不能改变状态');
        $updateid = $this->update_state('@@bank_list',$id);
        if(!$updateid) core::error('状态更新失败');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "状态更新成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/sys/banklist");',
            ),
        ));
    }
    //删除指定ID数据行（单行）
    public function banklist_delete(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if(!$id) core::__403();
        if($id==24) core::error('管理员充值不能删除');
        //删除条件检测
        //if($id<=4) core::error('系统默认数据无法删除');
        $deleteid = $this->db->delete('@@bank_list',array('id'=>$id));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/banklist");',
            ),
        ));
    }
    //删除选定数据行（多行）
    public function banklist_delete_list(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        $ids24 = ','.$ids.',';
        if(strpos($ids24,',24,')) core::error('管理员充值不能删除');
        if(empty($ids)) core::error('没有选择要删除的数据行');
        $delid = $this->mod_banklist_delete_list($ids);
        if(!$delid) core::error('删除失败');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/sys/banklist");',
            ),
        ));
    }
    //新增、编辑参数重组
    private function banklist_add_edit_args($get=false){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'id' => $this->existsKeyInArray('id',$para,'N'),
            'code' => $this->existsKeyInArray('code',$para,'S'),
            'title' => $this->existsKeyInArray('title',$para,'S'),
            'logo' => $this->existsKeyInArray('logo',$para,'S','#'),
            'urls' => $this->existsKeyInArray('urls',$para,'S','#'),
            'tel' => $this->existsKeyInArray('tel',$para,'S'),
            'sort' => $this->existsKeyInArray('sort',$para,'N'),
            'state' => $this->existsKeyInArray('state',$para,'N'),
        );
        if(empty($args['title'])) core::error('标题不能为空');
        return $args;
    }
    //保存新增的数据行
    public function banklist_add_save(){
        if(!$this->post) core::__403();
        $args = $this->banklist_add_edit_args(false);
        unset($args['id']);
        $insertid = $this->table_row_save('@@bank_list',$args);
        if(!$insertid) core::error('添加【'.$args['title'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$insertid,$args['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/banklist");',
            ),
        ));
    }
    //保存编辑的数据行
    public function banklist_edit_save(){
        if(!$this->post) core::__403();
        $args = $this->banklist_add_edit_args(false);
        $editid = $args['id'];
        unset($args['id']);
        $updateid = $this->table_row_save('@@bank_list',$args,array('id'=>$editid),true);
        if(!$updateid) core::error('更新【'.$args['title'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$updateid,$args['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/banklist");',
            ),
        ));
    }
    //endregion

    //region 充值通道
    //处理数据列表参数
    private function payway_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'sKey' => $this->existsKeyInArray('sKey',$para,'S'),
            'ps' => $this->existskeyInArray('ps',$para,'N',$this->pagesize),
        );
        return $args;
    }
    //处理数据列表分页参数
    private function payway_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function payway(){
        //获取参数
        $args = $this->payway_get_args(true);
        //获取当前页码
        $args['page_current'] = $this->get_page();
        //重组分布链接参数
        $page_args = $this->payway_page_args($args);
        //拉取条件数据
        $datas = $this->mod_payway_list($args);
        //计算数据最大分页数
        $args['page_max'] = $this->get_maxpage($args['ps'], $datas['record']);
        //显示模板
        $this->display('sys/payway',array(
            'basepath' => '/sys/payway',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //删除指定ID数据行（单行）
    public function payway_delete(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        // if($id==1 || $id==3) core::error('当前通道不能删除');
        if(!$id) core::__403();
        core::error('充值通道不能删除，不使用的请禁用即可');
        //删除条件检测
        //if($id<=4) core::error('系统默认数据无法删除');
        /*
        $deleteid = $this->db->delete('@@pay_way',array('id'=>$id));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/payway");',
            ),
        ));
        */
    }
    //新增行
    public function payway_add()
    {
        $this->display('sys/payway_add',array(
            'basepath' => '/sys/payway',
            'bankslist' => $this->mod_banklist_all(),
            'page_url' => '',
            'page_current' => 1,
            'maxsort' => 1,
        ));
    }
    //编辑行
    public function payway_edit(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if($id==1 || $id==3) core::error('当前通道不能编辑');
        $this->display('sys/payway_edit', array(
            'basepath' => '/sys/payway',
            'bankslist' => $this->mod_banklist_all(),
            'data' => $this->mod_payway_item($id),
        ));
    }
    //新增、编辑参数重组
    private function payway_add_edit_args($get=false){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'id' => $this->existsKeyInArray('id',$para,'N'),
            'title' => $this->existsKeyInArray('title',$para,'S'),
            'payclass' => $this->existsKeyInArray('payclass',$para,'S'),
            'info' => $this->existsKeyInArray('info',$para,'S'),
            'logo' => $this->existsKeyInArray('logo',$para,'S','#'),
            'memo' => $this->existsKeyInArray('memo',$para,'S'),
            'banks' => $this->existsKeyInArray('banks',$para,'S'),
            'payfrom' => $this->existsKeyInArray('payfrom',$para,'S'),
            'sort' => $this->existsKeyInArray('sort',$para,'N'),
            'state' => $this->existsKeyInArray('state',$para,'N'),
            'rechargemoney' => $this->existsKeyInArray('rechargemoney',$para,'S')
        );
        if(empty($args['title'])) core::error('通道标题不能为空');
        if(empty($args['payclass'])) core::error('须指定通道类名');
        return $args;
    }
    //保存新增的数据行
    public function payway_add_save(){
        if(!$this->post) core::__403();
        $args = $this->payway_add_edit_args(false);
        unset($args['id']);
        $insertid = $this->table_row_save('@@pay_way',$args);
        if(!$insertid) core::error('添加【'.$args['title'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$insertid,$args['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/payway");',
            ),
        ));
    }
    //保存编辑的数据行
    public function payway_edit_save(){
        if(!$this->post) core::__403();
        $args = $this->payway_add_edit_args(false);
        $editid = $args['id'];
        if($editid==1 || $editid==3) core::error('当前通道不能编辑');
        unset($args['id']);
        $updateid = $this->table_row_save('@@pay_way',$args,array('id'=>$editid),true);
        if(!$updateid) core::error('更新【'.$args['title'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$editid,$args['title']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/payway");',
            ),
        ));
    }
    //状态更新
    public function payway_state()
    {
        $id = $this->existsKeyInArray('id',$_REQUEST,'N');
        if(!$id) core::error('参数错误');
        if($id==1) core::error('管理员充值通道状态不能更改');
        $updateid = $this->update_state('@@pay_way',$id);
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "状态更新成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/sys/payway");',
            ),
        ));
    }
    //endregion

    //region 用户充值线路管理
    //处理数据列表参数
    private function rechargeline_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'sKey' => $this->existsKeyInArray('sKey',$para,'S'),
            'ps' => $this->existskeyInArray('ps',$para,'N',$this->pagesize),
        );
        return $args;
    }
    //处理数据列表分页参数
    private function rechargeline_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function rechargeline(){
        //获取参数
        $args = $this->rechargeline_get_args(true);
        //获取当前页码
        $args['page_current'] = $this->get_page();
        //重组分布链接参数
        $page_args = $this->rechargeline_page_args($args);
        //拉取条件数据
        $datas = $this->mod_rechargeline_list($args);
        //计算数据最大分页数
        $args['page_max'] = $this->get_maxpage($args['ps'], $datas['record']);
        //显示模板
        $this->display('sys/rechargeline',array(
            'basepath' => '/sys/rechargeline',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //新增、编辑参数重组
    private function rechargeline_add_edit_args($get=false){
        $para = $get ? $_GET : $_POST;
        $args = array(
            'id' => $this->existsKeyInArray('id',$para,'N'),
            'paywayid' => $this->existsKeyInArray('paywayid',$para,'N'),
            'bankid' => $this->existsKeyInArray('bankid',$para,'N'),
            'username' => $this->existsKeyInArray('username',$para,'S'),
            'account' => $this->existsKeyInArray('account',$para,'S'),
            'openadds' => $this->existsKeyInArray('openadds',$para,'S','#'),
            'memcode' => $this->existsKeyInArray('memcode',$para,'S'),
            'md5key' => $this->existsKeyInArray('md5key',$para,'S'),
            'rsaprikey' => $this->existsKeyInArray('rsaprikey',$para,'S'),
            'pubkey' => $this->existsKeyInArray('pubkey',$para,'S'),
            'posturl' => $this->existsKeyInArray('posturl',$para,'S'),
            'creurl' => $this->existsKeyInArray('creurl',$para,'S'),
            'give' => $this->existsKeyInArray('give',$para,'F'),
            'payfrom' => $this->existsKeyInArray('payfrom',$para,'S'),
            'sort' => $this->existsKeyInArray('sort',$para,'N'),
            'state' => $this->existsKeyInArray('state',$para,'N'),
        );
        if(intval($args['paywayid']) == 20 || intval($args['paywayid']) == 21){
            $args['posturl'] = $this->existsKeyInArray('qrcodeurl',$para,'S');
        }
        return $args;
    }

    //新增行
    public function rechargeline_add()
    {
        $this->display('sys/rechargeline_add',array(
            'basepath' => '/sys/rechargeline',
            'bankslist' => $this->mod_banklist_all(),
            'payway' => $this->mod_payway_select_item(),
            'page_url' => '',
            'page_current' => 1,
            'maxsort' => 1,
        ));
    }
    //编辑行
    public function rechargeline_edit(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if($id==1 || $id==2) core::error('当前充值线路不能编辑');
        $this->display('sys/rechargeline_edit', array(
            'basepath' => '/sys/rechargeline',
            'bankslist' => $this->mod_banklist_all(),
            'payway' => $this->mod_payway_select_item(),
            'data' => $this->mod_rechargeline_item($id),
        ));
    }

    //保存新增的数据行
    public function rechargeline_add_save(){
        if(!$this->post) core::__403();
        $args = $this->rechargeline_add_edit_args(false);
        unset($args['id']);
        $insertid = $this->table_row_save('@@rechargeline',$args);
        if(!$insertid) core::error('添加【'.$args['username'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$insertid,$args['username']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['username']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/rechargeline");',
            ),
        ));
    }
    //保存编辑的数据行
    public function rechargeline_edit_save(){
        if(!$this->post) core::__403();
        $args = $this->rechargeline_add_edit_args(false);
        $editid = $args['id'];
        if($editid==1 || $editid==2) core::error('当前充值线路不能编辑');
        unset($args['id']);
        $updateid = $this->table_row_save('@@rechargeline',$args,array('id'=>$editid),true);
        if(!$updateid) core::error('更新【'.$args['username'].'】失败');
        $this->addLog($this->authid,__FUNCTION__,$editid,$args['username']);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "更新[".$args['username']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/rechargeline");',
            ),
        ));
    }

    //删除单行
    public function rechargeline_delete()
    {
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if(!$id) core::__403();
        if($id==1 || $id==2) core::error('当前充值线路不能删除');
        //删除条件检测
        //if($id<=4) core::error('系统默认数据无法删除');
        $deleteid = $this->db->delete('@@rechargeline',array('id'=>$id));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/sys/rechargeline");',
            ),
        ));
    }
    //删除选定数据行（多行）
    /*
    public function rechargeline_delete_list(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        if(empty($ids)) core::error('没有选择要删除的数据行');
        $delid = $this->mod_recharge_delete_list($ids);
        if(!$delid) core::error('删除失败');
        $this->addLog($this->authid,__FUNCTION__,$delid,$ids);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/sys/rechargeline");',
            ),
        ));
    }
    */
    //状态更新
    public function rechargeline_state()
    {
        $id = $this->existsKeyInArray('id',$_REQUEST,'N');
        if(!$id) core::error('参数错误');
        if($id==1 && $id==2) core::error('当前线路不能改变状态');
        $updateid = $this->update_state('@@rechargeline',$id);
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "状态更新成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/sys/rechargeline");',
            ),
        ));
    }

    //endregion

    public function refreshRedisBtn($btnname)
    {
        echo '<a href="/cache/update?key='.$this->redisPrefix['SPAMS'].$btnname.'" class="button icon-undo" target="ajax" func="loadpage" title="更新Redis缓存"></a>';
    }

    //region 登录日志管理
    private function adminactionlog_get_args($get){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $args['username'] = $this->existsKeyInArray('username',$para,'S');
        $args['action'] = $this->existsKeyInArray('action',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,true,$this->pagesize);
        return $args;
    }
    private function adminactionlog_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    public function adminactionlog(){
        $get = true;
        $args = $this->adminactionlog_get_args($get);
        $page_args = $this->adminactionlog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_adminactionlog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);
        $this->display("sys/adminlog",array(
            'basepath' => '/sys/adminactionlog',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }

    public function adminlogdetail()
    {
        $id = $_GET['id'];

        $sql = "SELECT * FROM `@@admin_log` WHERE `id`='{$id}' LIMIT 1";
        $log = $this->db->query($sql,2);

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<dl><dt>记录ID：</dt><dd><input type="text" value="'.$log['id'].'" /> </dd></dl>';
        $html .= '<dl><dt>管理员账号：</dt><dd><input type="text" readonly value="'.$log['username'].'" /></dd></dl>';
        $html .= '<dl><dt>操作方法：</dt><dd><input type="text" readonly value="'.$log['action'].'" /></dd></dl>';
        $html .= '<dl><dt>操作ip：</dt><dd><input type="text" readonly value="'.$log['actionip'].'" /></dd></dl>';
        $html .= '<dl><dt>extfield0：</dt><dd><input type="text" value="'.$log['extfield0'].'" /> </dd></dl>';
        $html .= '<dl><dt>extfield1：</dt><dd><input type="text" value="'.$log['extfield1'].'" /> </dd></dl>';
        $html .= '<dl><dt>extfield1：</dt><dd><textarea name="" id="" cols="30" rows="10">'.$log['extfield2'].'</textarea> </dd></dl>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //endregion

}